package com.magold.game.factory;

import java.lang.reflect.Constructor;

import com.magold.io.XMLReader;
import com.magold.logic.Cloud;
import com.magold.logic.ISpriteLogic;
import com.magold.logic.bulb.Bulb;

/**
 * current supported class:
 * 	{@link Cloud}, {@link Bulb}
 * 
 * 
 * @author Eternity
 *
 */
public class SimpleLogicFactory extends BaseLogicFactory {
	private Constructor<? extends ISpriteLogic> mConstructor;
	
	public SimpleLogicFactory(Class<? extends ISpriteLogic> clazz) throws NoSuchMethodException {
		super(clazz.getSimpleName());
		
		mConstructor = clazz.getConstructor();
	}

	@Override
	protected ISpriteLogic createSafely(XMLReader pReader) {
		try {
			return mConstructor.newInstance();
		} catch (Exception e) {
			throw new DefaultConstructorFailedException();
		}
	}

}
